/** \file lp_test.c
 * \brief Tests the logic parser with some expressions in the cli.
 * \author Marcelo Lira dos Santos
 * \date 2006-2007
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License, see the file LICENSE.
 */
#include "logicparser.h"
#include "lp_graph.h"

void
show_tree(LpNode *node)
{
	if (node != NULL) {
		if (node->lpToken->nodeType == C_ID) {
			g_print("%c%d\n", node->lpToken->nodeType, node->lpToken->nodeId);
		} else {
			if (node->lpToken->nodeType == C_IF)
				g_print("->\n");
			else
				g_print("%c\n", node->lpToken->nodeType);
			show_tree(node->left);
			show_tree(node->right);
		}
	}
}

void
parse_expression (gchar *expr)
{
	LpNode *root;
	gchar *dotgraph;

	expr = g_ascii_strup (expr, -1);
	if ((root = lp_parse_expression(expr)) == NULL) {
		g_print("A expressao \"%s\" nao representa uma expressao valida.\n", expr);
	} else {
		g_print("Contemple a arvore parseada!\n");
		show_tree(root);
		g_print("\nE seu grafo!\n");
		dotgraph = lp_graph_generate (root);
		g_print("%s", lp_graph_generate (root));
	}
}

/*
int
main (int args, char* argv[])
{
	parse_expression("(p1->(f | (!p3)))");
	parse_expression("!(!(p1 & p2) | p3)"); //essa aqui dah um problema estranho
	parse_expression("(((!(!(p1 & p2) | p3))))");
	parse_expression("!(!(p1 & p2) | p3)");

	return 0;
}
*/
